package com.lzl;

import com.sun.org.apache.xml.internal.security.Init;
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import java.io.IOException;
import java.net.InetSocketAddress;

public class MinaServer {

    public static void main(String[] args) throws IOException {
        new MinaServer();
        System.out.println("服务器启动成功");
    }

    public MinaServer() throws IOException {
        init();
    }

    void init() throws IOException {
        NioSocketAcceptor acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors() + 1);
        //设置解析器
        DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
        chain.addLast("codec",new ProtocolCodecFilter(new TextLineCodecFactory()));

        acceptor.setHandler(new MinaServerHandler());
        acceptor.bind(new InetSocketAddress(8200));


    }


}
